#{extends 'assistant_main.html' /}

#{set "moreStyles"}
<style type="text/css">
</style>
#{/set}

#{set 'moreScripts'}

<script type="text/javascript">
    *{var listAction = #{jsAction @SysConstants.ajaxList() /}}*

    $(function () {
        // Tabs
        $(function () {
            $("#const_type_tabs").tabs({
                ajaxOptions:{
                    error:function (xhr, status, index, anchor) {
                        $(anchor.hash).html("载入失败");
                    }
                }
            });
            $( "#const_type_tabs" ).tabs( "option", "spinner", '获取数据中...' );
        });

        // -------- add const type dialog
        $('#add_const_type_div').dialog({
            autoOpen:false,
            width:400,
            modal:true,
            resizable: false,
            buttons:{
                "保存":function () {
                    if ($("#typeConstCode").val().trim() == "") {
                        jqAlert("请填写常量类型ID");
                    } else if(isNaN($("#typeConstCode").val())){
                        jqAlert("常量类型ID必须是整数");
                    }else if ($("#typeConstRemark").val().trim() == "") {
                        jqAlert("请填写常量类型名称");
                    }else{
                        $("#add_const_type_form").submit();
                        $(this).dialog("close");
                    }
                },
                "取消":function () {
                    $(this).dialog("close");
                }
            }
        });

        // -------- add const dialog
        $('#add_const_div').dialog({
            autoOpen:false,
            width:400,
            modal:true,
            resizable: false,
            buttons:{
                "保存":function () {
                    if ($("#constCode").val().trim() == "") {
                        jqAlert("请填写常量ID");
                    } else if (isNaN($("#constCode").val())) {
                        jqAlert("常量ID必须是整数");
                    } else if ($("#constValue").val().trim() == "") {
                        jqAlert("请填写常量值");
                    } else {
                        $("#add_const_form").submit();
                        $(this).dialog("close");
                    }
                },
                "取消":function () {
                    $(this).dialog("close");
                }
            }
        });


        // Dialog Link
        $('#create_const_type_link').click(function () {
            $('#add_const_type_div').css('display', '');
            $('#add_const_type_div').dialog('open');
            return false;
        });

        $('#create_const_link').click(function () {
            $('#add_const_div').css('display', '');
            $('#add_const_div').dialog('open');
            return false;
        });

        // -------- edit user dialog
        $('#edit_div').dialog({
            autoOpen:false,
            width:400,
            modal:true,
            resizable:false,
            buttons:{
                "保存":function () {
                    $("#edit_form").submit();
                    $(this).dialog("close");
                },
                "取消":function () {
                    $(this).dialog("close");
                }
            }
        });
    });


    var detailForEditAction = #{jsAction @SysConstants.detailForEdit(':id') /}

    function showEditForm(constId,constRemark) {
        $('#edit_table_div').load(detailForEditAction({id:constId}), function () {});
        $("#edit_const_id").val(constId);
        $('#edit_div').css('display', '');
        $('#edit_div').dialog('option', "title", "修改常量（" + constRemark + "）基本信息");
        $('#edit_div').dialog('open');
    };


    var constListAction = #{jsAction @SysConstants.constList(':id',':name') /}

    function showConstantsInTab(typeConstCode,typeConstRemark){
        $('#const_tab').load(constListAction({id:typeConstCode,name:typeConstRemark}), function () {});
        $("#const_tab_link").html(typeConstRemark);
        $('#const_type_tabs').tabs('select', 1);
    };

    var nextConstCodeAction = #{jsAction @SysConstants.nextConstCode(':constType') /}

    function freshMemory(){
        $.get('@{Application.reload()}', function (data) {
            $('#fresh_div').html(data);
            jqAlert("刷新完成：<br/>"+data);
        });
    }
</script>
#{/set}


<h1 id="title">常量管理</h1>
<div class="light_bar">
${constTypeList.size()} 常量类型
    &nbsp;
    <a href="#" id="create_const_type_link" class="ui-state-default ui-corner-all dialog_button">
        <span class="ui-icon ui-icon-newwin"></span>新增常量类型</a>
    <a href="#" id="create_const_link" class="ui-state-default ui-corner-all dialog_button">
        <span class="ui-icon ui-icon-newwin"></span>新增常量</a>

    *{<a href="#" class="ui-state-default ui-corner-all big_opt_button" onclick="freshMemory();" style="float: right">
        刷新系统常量</a>}*
</div>

*{#{pagination page:pageSequence ?: 1, size:entityCount /}}*

<div id="const_type_tabs">
    <ul>
        <li><a href="#const_type_tab">常量类型</a></li>
        <li><a id="const_tab_link" href="#const_tab">常量</a></li>
    </ul>

    <div id="const_type_tab">
        <table id="const_type_list">
            <thead>
            <tr>
                <th class="main" width="60px">类型ID</th>
                <th class="main">类型名称</th>
                <th class="main" width="80px">创建时间</th>
                <th width="200px">操作</th>
            </tr>
            </thead>
        #{if constTypeList.size()>0}
            #{list items:constTypeList, as:'en'}
                <tr>
                    <td class="main">${en.constCode}</td>
                    <td class="main">${en.constRemark}</td>
                    <td class="main">${en.createDate.format("yyyy-MM-dd")}</td>
                    <td class="main">
                        <a class="ui-state-default ui-corner-all opt_button"
                           href="javascript:showConstantsInTab('${en.constCode}','${en.constRemark}');">查看常量</a>
                        <a class="ui-state-default ui-corner-all opt_button"
                           href="javascript:requireActionByPost('@{SysConstants.delete}','${en.id}','确认删除常量类型(${en.constRemark})？类型下常量将同时被删除');">删除</a>
                    </td>
                </tr>
            #{/list}
        #{/if}

        </table>
    </div>


    <div id="const_tab">
*{load data by ajajxAction}*
    </div>
</div>

<div id="fresh_div" title="刷新结果" style="display: none"></div>


<div id="add_const_type_div" style="display: none;" title="新增常量类型">
    <form id="add_const_type_form" action="@{SysConstants.createType()}" method="post">
        <table class="myTable">
            <tr>
                <td align="right" class="input_label"><label for="typeConstCode" class="input_required">类型ID：</label></td>
                <td><input id="typeConstCode" name="typeConstCode" type="text" maxlength="50"/>
                    <script type="text/javascript">
                        $.get(nextConstCodeAction({constType:0}), function (next) {
                            $("#typeConstCode").val(next);
                        });
                    </script>
                </td>
            </tr>
            <tr class="no_bottom">
                <td align="right" class="input_label no_bottom"><label for="typeConstRemark" class="input_required">类型名称：</label></td>
                <td class="no_bottom"><input id="typeConstRemark" name="typeConstRemark" type="text" maxlength="50"/></td>
            </tr>
        </table>
    </form>
</div>


<div id="add_const_div" style="display: none;" title="新增常量">
    <form id="add_const_form" action="@{SysConstants.create}" method="post">
        <table class="myTable">
            <tr>
                <td align="right" class="input_label"><label for="typeConstCodeSel" class="input_required">常量类型：</label></td>
                <td>
                    <select id="typeConstCodeSel" name="constType" onchange="javascript:
                    $.get(nextConstCodeAction({constType:$('#typeConstCodeSel').val()}), function (next) {$('#constCode').val(next);});">
                    #{if constTypeList!=null && constTypeList.size()>0}
                        #{list items:constTypeList, as:'ct'}
                            <option value="${ct.constCode}">${ct.constRemark}</option>
                        #{/list}
                    #{/if}
                    </select>
                    <script type="text/javascript">
                        $.get(nextConstCodeAction({constType:$("#typeConstCodeSel").val()}), function (next) {
                            $("#constCode").val(next);
                        });
                    </script>
                </td>
            </tr>
            <tr>
                <td align="right" class="input_label"><label for="constCode" class="input_required">常量ID：</label></td>
                <td><input id="constCode" name="constCode" type="text" maxlength="50"/></td>
            </tr>
            <tr>
                <td align="right" class="input_label"><label for="constValue" class="input_required">常量值：</label></td>
                <td><input id="constValue" name="constValue" type="text" maxlength="50"/></td>
            </tr>
            <tr class="no_bottom">
                <td align="right" class="input_label no_bottom"><label for="constRemark" >常量备注：</label></td>
                <td class="no_bottom">
                    <input id="constRemark" name="constRemark" type="text" maxlength="20"/>
                </td>
            </tr>
        </table>
    </form>
</div>